<%@ page language="java"
         contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"
         import="com.shxt.hotel.background.*"
         import="java.util.Map"
         import="java.util.List"
%>
<%
    Room room = new Room();
    Staff staff = new Staff();
    
    if(session.getAttribute("staff_id") == null){
        response.sendRedirect("./login.jsp");
    }else{
        // get current Staff
        request.setCharacterEncoding("UTF-8");
        int staff_id = (int)session.getAttribute("staff_id");
        
        Map<String, Object> currentStaff = staff.getStaffInfo(staff_id).get(0);
%>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="Mosaddek">
    <link rel="shortcut icon" href="../Public/img/favicon.html">

    <title>Sub Overview</title>

    <!-- Bootstrap core CSS -->
    <link href="../Public/css/bootstrap.min.css" rel="stylesheet">
    <link href="../Public/css/bootstrap-reset.css" rel="stylesheet">
    <!--external css-->
    <link href="../Public/assets/font-awesome/css/font-awesome.css" rel="stylesheet" />
    <!-- Custom styles for this template -->
    <link href="../Public/css/style.css" rel="stylesheet">
    <link href="../Public/css/style-responsive.css" rel="stylesheet" />

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 tooltipss and media queries -->
    <!--[if lt IE 9]>
      <script src="../Public/js/html5shiv.js"></script>
      <script src="../Public/js/respond.min.js"></script>
    <![endif]-->
</head>

<body>

    <section id="container" class="">
        <!--header start-->
        <jsp:include page="./Public/header.jsp" flush="true"/>
        <!--header end-->
        <!--sidebar start-->
        <jsp:include page="./Public/sidebar.jsp" flush="true"/>
        <!--sidebar end-->
        <!--main content start-->
        <section id="main-content">
            <section class="wrapper">
                <!-- page start-->
                <div class="row">
                    <div class="col-lg-12">
                        <section class="panel panel-primary">
                            <header class="panel-heading">
                                Subscribe Overview
                            </header>
                            <%
                                List<Map<String, Object>> subInfo = room.getSubInfo();
                                if(subInfo.size() != 0){
                                    List<Map<String, Object>> subRoomList = room.getSubRooms();
                                    List<Map<String, Object>> cateList = room.getCategories("*");
                            %>
                            <table class="table table-striped border-top" id="sample_1">
                                <thead>
                                    <tr>
                                        <th style="width:8px;"><input type="checkbox" class="group-checkable" data-set="#sample_1 .checkboxes" /></th>
                                        <th>Room Type</th>
                                        <th class="hidden-phone">Room ID</th>
                                        <th class="hidden-phone">User ID</th>
                                        <th class="hidden-phone">Deposit</th>
                                        <th class="hidden-phone">Create Time</th>
                                        <th class="hidden-phone">End Time</th>
                                        <th class="hidden-phone">Area</th>
                                        <th>Sub Time</th>
                                        <th class="hidden-phone">Operation</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <%
                                        for(int i = 0; i < subRoomList.size(); i++){
                                            Map<String, Object> cate = cateList.get((int)subRoomList.get(i).get("category"));
                                            Map<String, Object> room_rec = subRoomList.get(i);
                                            Map<String, Object> sub_rec = null;
                                            for(int j = 0; j < subInfo.size(); j++){
                                                if((int)subInfo.get(j).get("rid") == (int)room_rec.get("id")){
                                                    sub_rec = subInfo.get(j);
                                                    break;
                                                }
                                            }
                                    %>
                                    <tr>
                                        <td><input type="checkbox" class="checkboxes" value="1" /></td>
                                        <td><%=cate.get("title") %></td>
                                        <td class="hidden-phone"><%=room_rec.get("id") %></td>
                                        <td class="hidden-phone"><%=sub_rec.get("uid") %></td>
                                        <td class="hidden-phone"><%=sub_rec.get("deposit") %>$</td>
                                        <td class="hidden-phone"><%=sub_rec.get("create_date") %></td>
                                        <td class="hidden-phone"><%=sub_rec.get("end_date") %></td>
                                        <td class="hidden-phone"><%=cate.get("area_min") + " ~ " + cate.get("area_max") %>mm</td>
                                        <td><%=cate.get("sub_time") %></td>
                                        <td class="hidden-phone">
                                            <button class="btn btn-success btn-xs" type="button" data-toggle="modal" href="#Renewal_modal">
                                                <i class="icon-edit"></i>
                                                Renewal
                                            </button>
                                            <a href='./sub_checkout.jsp?id=<%=sub_rec.get("id") %>'>
                                                <button class="btn btn-warning btn-xs" type="button">
                                                    <i class="icon-trash"></i>                                                
                                                    Check-out
                                                </button>
                                            </a>
                                        </td>
                                        <!-- Modal -->
                                        <div class="modal fade" id="Renewal_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                            <div class="modal-dialog">
                                                <div class="modal-content">
                                                    <form role="form" action="./sub_renewal.jsp" action="post">
                                                        <div class="modal-header">
                                                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                                            <h4 class="modal-title">Room Renewal</h4>
                                                        </div>
                                                        <div class="modal-body">
                                                                <input type="hidden" name="id" value='<%=sub_rec.get("id") %>'>
                                                                <div class="row">
                                                                    <div class="form-group">
                                                                        <label class="control-label col-lg-4">Renewal Days</label>
                                                                        <div class="col-lg-8">
                                                                            <input class="form-control" type="text" name="renewal_day" value="" autocomplete="off">
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                                <br/>
                                                                
                                                        </div>
                                                        <div class="modal-footer">
                                                            <button class="btn btn-info" type="submit">Renewal</button>
                                                            <button data-dismiss="modal" class="btn btn-danger" type="button">Close</button>
                                                        </div>
                                                    </form>
                                                </div>
                                            </div>
                                        </div>
                                        <!-- modal -->
                                    </tr>
                                    <%
                                        }
                                    %>
                                </tbody>
                            </table>
                            <%
                                }
                            %>
                        </section>
                    </div>
                </div>
                <!-- page end-->
            </section>
        </section>
        <!--main content end-->
    </section>

    <!-- js placed at the end of the document so the pages load faster -->
    <script src="../Public/js/jquery.js"></script>
    <script src="../Public/js/bootstrap.min.js"></script>
    <script src="../Public/js/jquery.scrollTo.min.js"></script>
    <script src="../Public/js/jquery.nicescroll.js" type="text/javascript"></script>
    <script type="text/javascript" src="../Public/assets/data-tables/jquery.dataTables.js"></script>
    <script type="text/javascript" src="../Public/assets/data-tables/DT_bootstrap.js"></script>


    <!--common script for all pages-->
    <script src="../Public/js/common-scripts.js"></script>

    <!--script for this page only-->
    <script src="../Public/js/dynamic-table.js"></script>
    
    <!--scripted by myself-->
    <script>
        $(document).ready(function(){
            $("#Hotel_Subscribe").addClass("active");
            $("#sub_overview").addClass("active");
        });
    </script>

</body>

</html>
<%
    }
%>